package com.gamehouse.eggpoacher;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;

public class myOptions extends Activity implements View.OnClickListener{
	Button bt_Reset;
	AlertDialog.Builder alertbox;
	
	CheckBox musicOption;
	CheckBox soundOption;
	CheckBox vibratorOption;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN );
	setContentView(R.layout.options);
	
		this.musicOption = (CheckBox) findViewById(R.id.checkBox1);
		this.soundOption = (CheckBox) findViewById(R.id.checkBox2);
		this.vibratorOption = (CheckBox) findViewById(R.id.checkBox3);
		this.bt_Reset = (Button)findViewById(R.id.bt_Reset);
		//this.bt_Reset.setOnClickListener(this);
		
		
		getOptions();
	}
	
	public void mostrarMenu(View view){
		//Intent myIntent = new Intent(view.getContext(), myMenu.class);
		//startActivityForResult(myIntent, 0);
		finish();
	}

	public void onClick(View arg0) {
		//AQUI APAGO SCORES e actual SCORE
		
		// prepare the alert box
		alertbox = new AlertDialog.Builder(this);
		// set the message to display
	    alertbox.setMessage("Are you sure you want to reset all Scores?");
	    // add a neutral button to the alert box and assign a click listener
	    alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
	    // click listener on the alert box
	    public void onClick(DialogInterface arg0, int arg1) {
	    // the button was clicked
	    	Context context = getApplicationContext();
	    	DataBaseAdapter db = new DataBaseAdapter(context);
			db.open();
			db.resetScores();
			db.close();
	
	    }
	    
	    });
	    alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
		    public void onClick(DialogInterface arg2, int arg3){}});
	    alertbox.show();
	}
	
	public void saveChanges (View view)
	{
		int music = 1;
		int sound = 1;
		int vibrator = 1;
		
		if (musicOption.isChecked())
		{
			music = 0;
		}
		if (soundOption.isChecked())
		{
			music = 0;
		}
		if (vibratorOption.isChecked())
		{
			music = 0;
		}
	
		 DataBaseAdapter db = new DataBaseAdapter(this);
		 db.open();
		 db.updateOptions(sound, music, vibrator);
		 db.close();

	}
	
	public void getOptions () 
	{

		 DataBaseAdapter db = new DataBaseAdapter(this);
		 db.open();
		 Cursor c = db.getAllOptions();
		 if (c.moveToFirst())
	        {
	        	do {  
	        		if(c.getInt(0) == 0)
	        		{
	        			soundOption.setChecked(true);
	        		}else
	        		{
	        			soundOption.setChecked(false);
	        		}
	        		
	        		if(c.getInt(1) == 0)
	        		{
	        			musicOption.setChecked(true);
	        		}else
	        		{
	        			musicOption.setChecked(false);
	        		}
	        		
	        		if(c.getInt(1) == 0)
	        		{
	        			vibratorOption.setChecked(true);
	        		}else
	        		{
	        			vibratorOption.setChecked(false);
	        		}
	        	} while (c.moveToNext());
	        	}
	     c.close();
		 db.close();
	}
}
